if (SERVER) then

	AddCSLuaFile( "shared.lua" )
	SWEP.Weight				= 5
	SWEP.AutoSwitchTo		= false
	SWEP.AutoSwitchFrom		= false
	SWEP.HoldType			= "pistol"

end

if ( CLIENT ) then

	SWEP.ViewModelFOV		= 75
	
	SWEP.IconFont = "CSSelectIcons"
	
	SWEP.ViewModelFlip		= false
	
	SWEP.PrintName = "Dual Berettas"
	SWEP.Slot = 2
	SWEP.Slotpos = 1
	SWEP.IconLetter = "s"
	
	killicon.AddFont( "weapon_berettas_tp", "CSKillIcons", SWEP.IconLetter, Color( 255, 80, 0, 255 ) )

end

 SWEP.Base				= "tp_base"
 
 SWEP.IronSightsPos = Vector (4.4046, 0.5407, 2.4549)
 SWEP.IronSightsAng = Vector (1.3226, 0.363, -1.2109)

 SWEP.Spawnable = true;
 SWEP.AdminSpawnable = true;

 SWEP.ViewModel			= "models/weapons/v_pist_elite.mdl"
 SWEP.WorldModel			= "models/weapons/w_alyx_gun.mdl"

 SWEP.Primary.Sound			= Sound( "weapons/elite/elite-1.wav" )
 SWEP.Primary.Recoil			= 2.9
 SWEP.Primary.Damage			= 16
 SWEP.Primary.NumShots		      = 1
 SWEP.Primary.Cone			= 0.022
 SWEP.Primary.ClipSize              = 30
 SWEP.Primary.Delay			= 0.17
 SWEP.Primary.Automatic             = false
 SWEP.Primary.Ammo                  = "pistol"

 SWEP.Secondary.Clipsize            = -1;
 SWEP.Secondary.DefaultClip         = -1;
 SWEP.Secondary.Automatic           = false
 SWEP.Secondary.Ammo                = "none"; 
 SWEP.Secondary.Delay			= 4
 
 SWEP.Anims = {}
 SWEP.Anims[1] = ACT_VM_SECONDARYATTACK
 SWEP.Anims[2] = ACT_VM_PRIMARYATTACK
 
 SWEP.Pos = 1

function SWEP:GetWorldModel()
	return "models/weapons/w_pist_elite_dropped.mdl"
end

function SWEP:SecondaryAttack()

end

function SWEP:ShootBullets( damage, numbullets, aimcone)

	local scale = 1
	local canscale = true
	if self.Owner:KeyDown(IN_DUCK) then
		scale = math.Clamp(aimcone/2,0,10)
		canscale = false
	elseif self.Owner:KeyDown(IN_WALK) and canscale then
		if self.Owner:KeyDown(IN_FORWARD) or self.Owner:KeyDown(IN_BACK) or self.Owner:KeyDown(IN_MOVELEFT) or self.Owner:KeyDown(IN_MOVERIGHT) then
			scale = math.Clamp(aimcone/2,0,10)
			canscale = false
		end
	elseif (self.Owner:KeyDown(IN_SPEED) or self.Owner:KeyDown(IN_JUMP)) and canscale then
		scale = aimcone + (aimcone*2)
		canscale = false
	elseif (self.Owner:KeyDown(IN_FORWARD) or self.Owner:KeyDown(IN_BACK) or self.Owner:KeyDown(IN_MOVELEFT) or self.Owner:KeyDown(IN_MOVERIGHT)) and canscale then
		scale = aimcone + (aimcone*1.5)
	else
		scale = aimcone
	end
	
	local recoil = self.Weapon:GetRecoilRatio()
	scale = scale * recoil
	
	local irons = self.Weapon:GetNetworkedBool( "Ironsights", false )
	local tracer = 1
	if irons then
		tracer = 90
	end
	
	local bullet = {}
	bullet.Num 		= numbullets
	bullet.Src 		= self.Owner:GetShootPos()			
	bullet.Dir 		= self.Owner:GetAimVector()			
	bullet.Spread 	= Vector( scale, scale, 0 )		
	bullet.Tracer	= tracer		
	bullet.Force	= math.Round(damage * 1.5)							
	bullet.Damage	= math.Round(damage * GameInfo.HumanDamageScale)
	bullet.AmmoType = "Pistol"
	bullet.TracerName 	= "Tracer"
	bullet.Callback = function ( attacker, tr, dmginfo )
		if tr.HitWorld or not tr.Entity then return end
		if not tr.Entity:IsPlayer() and not string.find(tr.Entity:GetClass(),"npc") then return end
		if tr.HitGroup == 1 and tr.Entity:IsValid() then
			local t2 = {}
			t2.start = tr.HitPos
			t2.endpos = self.Owner:GetAimVector() * 500
			t2.filter = tr.Entity
			local tr2 = util.TraceLine(t2)
			util.Decal("Blood", tr2.HitPos + tr2.HitNormal, tr2.HitPos - tr2.HitNormal)
			local effectdata = EffectData()
			effectdata:SetEntity(tr.Entity)
			effectdata:SetNormal(tr.HitNormal)
			effectdata:SetOrigin(tr.HitPos)
			util.Effect("headshot", effectdata)
			if math.random(1,3) == 1 then
				local effectdata = EffectData()
				effectdata:SetAngle(self.Owner:GetAimVector():Angle())
				effectdata:SetOrigin(tr.HitPos)
				util.Effect("head_gib", effectdata)
			end
			tr.Entity:EmitSound(ChooseRandom(GameSounds.HeadShot), 100, math.random(90,120))
		else
			util.Decal("Blood", tr.HitPos + tr.HitNormal, tr.HitPos - tr.HitNormal)
			local effectdata = EffectData()
			effectdata:SetOrigin(tr.HitPos)
			effectdata:SetNormal(tr.HitNormal)
			util.Effect("bodyshot", effectdata)
			local t2 = {}
			t2.start = tr.HitPos
			t2.endpos = self.Owner:GetAimVector() * 500
			t2.filter = tr.Entity
			local tr2 = util.TraceLine(t2)
			util.Decal("Blood", tr2.HitPos + tr2.HitNormal, tr2.HitPos - tr2.HitNormal)
		end
	end
	
	self.Owner:FireBullets( bullet )
	
	self.Weapon:SendWeaponAnim( self.Anims[self.Pos] ) 		// View model animation
	self.Pos = self.Pos + 1
	if self.Pos > 2 then
		self.Pos = 1
	end
	//self.Owner:MuzzleFlash()							// Crappy muzzle light
	self.Owner:SetAnimation( PLAYER_ATTACK1 )			// 3rd Person Animation
	
end